package f.admin.bo.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import f.admin.bo.entity.BOModule;
import f.admin.bo.service.BOModuleService;
import f.tools.DepUtil;

@WebServlet(name = "BOModuleServlet", urlPatterns = {"/boModule"})
public class BOModuleServlet extends HttpServlet {

	private BOModuleService boModuleService = new BOModuleService();
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String action = req.getParameter("action");
		if(action.equals("addBOModule")) {
			String name = req.getParameter("name");
			try {
				boModuleService.addBOModule(name);
				resp.getWriter().write("success");
			} catch (Exception e) {
				resp.getWriter().write("failure");
				e.printStackTrace();
			}
		} else if(action.equals("loadBOModule")) {
			try {
				List<BOModule> boModuleList = boModuleService.getBOModuleList();
				resp.getWriter().write(DepUtil.toJSONArray(boModuleList).toString());
			} catch(Exception e) {
				e.printStackTrace();
			}
		}
	}
}
